– Find significant events based on depth, magnitude, and
intensity.
– Focus on the tools used in earthquake
analysis.
– Display outlying observations in a
graphically asestetic way.
# create a spatial dataframe of the geojson file.
spdf <- geojson_read(here("data", "shakemap.geojson"), what="sp")
df <- as.data.frame(spdf)
# create dataframe from the CSV.
eq_csv <- read_csv(here("data", "2.5_month.csv"), show_col_types = FALSE)
# parse out time columns, create 'magAll', and drop uneccessary variables.
eq_new <- eq_csv %>%
separate(time, c("year", "month", "day"), remove = FALSE) %>%
mutate(magAll = mag > mean(mag, na.rm = TRUE)) %>%
select(id, year, month, day, depth, magAll, depthError)
# select, desired columns, rename certain variables, and sort by magnitude.
eq_df <- left_join(eq_new, df, by='id') %>%
select(year, month, day, depth, depthError, magAll, mag, magType, place, felt, cdi, mmi, sig, net, title) %>%
rename(intensity = mmi, intensityMax = cdi, magnitude = mag, significance = sig) %>%
arrange(-magnitude)
select_all(eq_df)
p <- eq_df %>%
filter(intensity > 0) %>%
ggplot(aes(x = depth, y = magnitude, color = intensity, size = magnitude)) +
geom_jitter(alpha = 0.7) +
scale_color_distiller(palette = "Spectral", direction = -1) +
ggtitle("USGS Earthquakes (Magnitude VS Depth)")
ggplotly(p, width = 900, height = 600, tooltip = c("x", "y", "color"))
# facet wrap -----------
p <- eq_df %>%
filter(!is.na(magType)) %>%
ggplot(aes(x = depth, y = magnitude, color = magnitude)) +
geom_jitter(alpha = 0.7) +
scale_color_distiller(palette = "Reds", direction = 1) +
facet_wrap(~ magType) +
ggtitle("USGS Earthquakes (Magnitude Type)")
ggplotly(p, width = 900, height = 600, tooltip = c("x", "y"))
p <- eq_df %>%
filter(intensity > 0) %>%
ggplot(aes(x = day, y = significance, color = significance, size = magnitude, title = title)) +
geom_jitter(alpha = 0.7) +
scale_color_distiller(palette = "Purples", direction = 1) +
ggtitle("USGS Earthquakes (Most Significant)")
ggplotly(p, width = 900, height = 600, tooltip = c("title", "y"))
# export plot to .jpg with ggsave
ggsave(here("data", "sig_quakes.jpg"))